package com.service.impl;

import com.mapper.DepartmentMapper;
import com.pojo.Department;
import com.service.DepartmentService;
import com.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class DepartmentServiceImpl implements DepartmentService {

    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();

    @Override
    public String selectDeptNameById(int dept_id) {
        SqlSession sqlSession = sqlSessionFactory.openSession();

        DepartmentMapper mapper = sqlSession.getMapper(DepartmentMapper.class);
        Department department = mapper.getById(dept_id);
        String deptName = department.getDeptName();

        sqlSession.close();
        return deptName;
    }

    @Override
    public int selectIdByDeptName(String deptName) {
        SqlSession sqlSession = sqlSessionFactory.openSession();

        DepartmentMapper mapper = sqlSession.getMapper(DepartmentMapper.class);
        Department department = mapper.getByDeptName(deptName);
        int id = department.getId();

        sqlSession.close();
        return id;
    }
}
